package com.feilong.edgeAI.remind.room.adapter;

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.feilong.edgeAI.R;
import com.feilong.edgeAI.remind.room.bean.RemindBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class RemindListAdapter extends RecyclerView.Adapter<RemindListAdapter.ViewHolder> {
    private List<RemindBean> mRemindList;
    private OnItemClickListener mListener;

    public RemindListAdapter(List<RemindBean> RemindBeans) {
        this.mRemindList = RemindBeans;
        notifyItemChanged(RemindBeans.size());
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_phone_text, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, @SuppressLint("RecyclerView") int position) {

        holder.tv_day.setText(position +1 +". "+mRemindList.get(position).getDay());
        holder.tv_minute.setText(mRemindList.get(position).getHour());
        holder.tv_message.setText(mRemindList.get(position).getMessage());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onItemClick(mRemindList.get(position));
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return mRemindList == null ? 0 : mRemindList.size();
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }


    private String getFormatDate(Date date) {
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(date);
    }

    public interface OnItemClickListener {
        void onItemClick(RemindBean remindBean);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_day,tv_minute,tv_message;

        private ViewHolder(View itemView) {
            super(itemView);
            tv_day = itemView.findViewById(R.id.tv_day);
            tv_minute = itemView.findViewById(R.id.tv_minute);
            tv_message = itemView.findViewById(R.id.message);
        }
    }
    
}
